Micron Document
`:top
A `!Java class file`! is a `F33f`_`[file`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Computer_file]`_`f (with the .class `F33f`_`[filename extension`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Filename_extension]`_`f) containing `F33f`_`[Java bytecode`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_bytecode]`_`f that can be executed on the `F33f`_`[Java Virtual Machine (JVM)`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_virtual_machine]`_`f. A Java class file is usually produced by a `F33f`_`[Java compiler`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_compiler]`_`f from `F33f`_`[Java programming language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f `F33f`_`[source files`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Source_file]`_`f (.java files) containing Java `F33f`_`[classes`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Class_(programming)]`_`f (alternatively, other `F33f`_`[JVM languages`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JVM_languages]`_`f can also be used to create class files). If a source file has more than one class, each class is compiled into a separate class file. Thus, it is called a .class file because it contains the bytecode for a single class.

JVMs are available for many `F33f`_`[platforms`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Platform_(computing)]`_`f, and a class file compiled on one platform will execute on a JVM of another platform. This makes Java applications `F33f`_`[platform-independent`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Cross-platform]`_`f.

>>Contents

• `F0af`_`[History`#history]`_`f
• `F0af`_`[File layout and structure`#file-layout-and-structure]`_`f
• `F0af`_`[Sections`#sections]`_`f
• `F0af`_`[Magic Number`#magic-number]`_`f
• `F0af`_`[General layout`#general-layout]`_`f
• `F0af`_`[Representation of a class file`#representation-of-a-class-file]`_`f
• `F0af`_`[The constant pool`#the-constant-pool]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[Further reading`#further-reading]`_`f

-─

>>History

On 11 December 2006, the class file format was modified under `F33f`_`[Java Specification Request`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Specification_Request]`_`f (JSR) 202.`:cite-ref-1[`F5bf`_`[1`#cite-note-1]`_`f]

>>File layout and structure

>>>Sections

There are 10 basic sections to the Java class file structure:

• `!`F33f`_`[Magic Number`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Magic_number_(programming)]`_`f`!: `B100`F9d90xCAFEBABE`f`b
• `!Version of Class File Format`!: the minor and major versions of the class file
• `!Constant Pool`!: Pool of constants for the class
• `!Access Flags`!: for example whether the class is abstract, static, etc.
• `!This Class`!: The name of the current class
• `!`F33f`_`[Super Class`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Superclass_(computer_science)]`_`f`!: The name of the super class
• `!`F33f`_`[Interfaces`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Interface_(object-oriented_programming)]`_`f`!: Any interfaces in the class
• `!Fields`!: Any fields in the class
• `!`F33f`_`[Methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Method_(computer_programming)]`_`f`!: Any methods in the class
• `!Attributes`!: Any attributes of the class (for example the name of the sourcefile, etc.)

>>>Magic Number

Class files are identified by the following 4 `F33f`_`[byte`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Byte]`_`f `F33f`_`[header`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Header_(computing)]`_`f (in `F33f`_`[hexadecimal`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Hexadecimal]`_`f): `B100`F9d9CA FE BA BE`f`b (the first 4 entries in the table below). The history of this `F33f`_`[magic number`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Magic_number_(programming)]`_`f was explained by `F33f`_`[James Gosling`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=James_Gosling]`_`f referring to a restaurant in `F33f`_`[Palo Alto`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Palo_Alto,_California]`_`f:`:cite-ref-2[`F5bf`_`[2`#cite-note-2]`_`f]

`*"We used to go to lunch at a place called St Michael's Alley. According to local legend, in the deep dark past, the `F33f`_`[Grateful Dead`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Grateful_Dead]`_`f used to perform there before they made it big. It was a pretty funky place that was definitely a Grateful Dead Kinda Place. When `F33f`_`[Jerry`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Jerry_Garcia]`_`f died, they even put up a little Buddhist-esque shrine. When we used to go there, we referred to the place as Cafe Dead. Somewhere along the line it was noticed that this was a HEX number. I was re-vamping some file format code and needed a couple of `F33f`_`[magic numbers`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Magic_number_(programming)]`_`f: one for the persistent object file, and one for classes. I used CAFEDEAD for the object file format, and in `F33f`_`[grepping`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Grep]`_`f for 4 character hex words that fit after "CAFE" (it seemed to be a good theme) I hit on BABE and decided to use it. At that time, it didn't seem terribly important or destined to go anywhere but the trash-can of history. So CAFEBABE became the class file format, and CAFEDEAD was the persistent object format. But the persistent object facility went away, and along with it went the use of CAFEDEAD - it was eventually replaced by `F33f`_`[RMI`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_remote_method_invocation]`_`f."`*

>>>General layout

Because the class file contains variable-sized items and does not also contain embedded file offsets (or pointers), it is typically parsed sequentially, from the first byte toward the end. At the lowest level the file format is described in terms of a few fundamental data types:

• `!u1`!: an unsigned `F33f`_`[8-bit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Octet_(computing)]`_`f integer
• `!u2`!: an unsigned `F33f`_`[16-bit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=16-bit]`_`f integer in `F33f`_`[big-endian`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Endianness]`_`f byte order
• `!u4`!: an unsigned `F33f`_`[32-bit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=32-bit]`_`f integer in big-endian byte order
• `!table`!: an array of variable-length items of some type. The number of items in the table is identified by a preceding count number (the count is a u2), but the size in bytes of the table can only be determined by examining each of its items.

Some of these fundamental types are then re-interpreted as higher-level values (such as strings or floating-point numbers), depending on context. There is no enforcement of word alignment, and so no padding bytes are ever used. The overall layout of the class file is as shown in the following table.

`t
| Byte offset | Size | Type or value |
|---|---|---|
| 0 | 4 bytes | u1 = 0xCA hex |
| 1 | 4 bytes | u1 = 0xFE hex |
| 2 | 4 bytes | u1 = 0xBA hex |
| 3 | 4 bytes | u1 = 0xBE hex |
| 4 | 2 bytes | u2 |
| 5 | 2 bytes | u2 |
| 6 | 2 bytes | u2 |
| 7 | 2 bytes | u2 |
| 8 | 2 bytes | u2 |
| 9 | 2 bytes | u2 |
| 10 | cpsize (variable) | table |
| ... | cpsize (variable) | table |
| ... | cpsize (variable) | table |
| ... | cpsize (variable) | table |
| 10+ cpsize | 2 bytes | u2 |
| 11+ cpsize | 2 bytes | u2 |
| 12+ cpsize | 2 bytes | u2 |
| 13+ cpsize | 2 bytes | u2 |
| 14+ cpsize | 2 bytes | u2 |
| 15+ cpsize | 2 bytes | u2 |
| 16+ cpsize | 2 bytes | u2 |
| 17+ cpsize | 2 bytes | u2 |
| 18+ cpsize | isize (variable) | table |
| ... | isize (variable) | table |
| ... | isize (variable) | table |
| ... | isize (variable) | table |
| 18+ cpsize + isize | 2 bytes | u2 |
| 19+ cpsize + isize | 2 bytes | u2 |
| 20+ cpsize + isize | fsize (variable) | table |
| ... | fsize (variable) | table |
| ... | fsize (variable) | table |
| ... | fsize (variable) | table |
| 20+ cpsize + isize + fsize | 2 bytes | u2 |
| 21+ cpsize + isize + fsize | 2 bytes | u2 |
| 22+ cpsize + isize + fsize | msize (variable) | table |
| ... | msize (variable) | table |
| ... | msize (variable) | table |
| ... | msize (variable) | table |
| 22+ cpsize + isize + fsize + msize | 2 bytes | u2 |
| 23+ cpsize + isize + fsize + msize | 2 bytes | u2 |
| 24+ cpsize + isize + fsize + msize | asize (variable) | table |
| ... | asize (variable) | table |
| ... | asize (variable) | table |
| ... | asize (variable) | table |
`t

`t
| Byte offset | Description |
|---|---|
| 0 | magic number (CAFEBABE) used to identif… |
| 1 | magic number (CAFEBABE) used to identif… |
| 2 | magic number (CAFEBABE) used to identif… |
| 3 | magic number (CAFEBABE) used to identif… |
| 4 | minor version number of the class file… |
| 5 | minor version number of the class file… |
| 6 | major version number of the class file… |
| 7 | major version number of the class file… |
| 8 | constant pool count, number of entries… |
| 9 | constant pool count, number of entries… |
| 10 | constant pool table, an array of variab… |
| ... | constant pool table, an array of variab… |
| ... | constant pool table, an array of variab… |
| ... | constant pool table, an array of variab… |
| 10+ cpsize | access flags, a bitmask |
| 11+ cpsize | access flags, a bitmask |
| 12+ cpsize | identifies this class, index into the c… |
| 13+ cpsize | identifies this class, index into the c… |
| 14+ cpsize | identifies super class, index into the… |
| 15+ cpsize | identifies super class, index into the… |
| 16+ cpsize | interface count, number of entries in t… |
| 17+ cpsize | interface count, number of entries in t… |
| 18+ cpsize | interface table: a variable-length arra… |
| ... | interface table: a variable-length arra… |
| ... | interface table: a variable-length arra… |
| ... | interface table: a variable-length arra… |
| 18+ cpsize + isize | field count, number of entries in the f… |
| 19+ cpsize + isize | field count, number of entries in the f… |
| 20+ cpsize + isize | field table, variable length array of f… |
| ... | field table, variable length array of f… |
| ... | field table, variable length array of f… |
| ... | field table, variable length array of f… |
| 20+ cpsize + isize + fsize | method count, number of entries in the… |
| 21+ cpsize + isize + fsize | method count, number of entries in the… |
| 22+ cpsize + isize + fsize | method table, variable length array of… |
| ... | method table, variable length array of… |
| ... | method table, variable length array of… |
| ... | method table, variable length array of… |
| 22+ cpsize + isize + fsize + msize | attribute count, number of entries in t… |
| 23+ cpsize + isize + fsize + msize | attribute count, number of entries in t… |
| 24+ cpsize + isize + fsize + msize | attribute table, variable length array… |
| ... | attribute table, variable length array… |
| ... | attribute table, variable length array… |
| ... | attribute table, variable length array… |
`t

>>>Representation of a class file

The following is a representation of a .class file as if it were a C-style struct.

`B100`F9d9struct ClassFileFormat {`f`b
`B100`F9d9 u4 magicNumber;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 minorVersion;`f`b
`B100`F9d9 u2 majorVersion;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 constantPoolCount;`f`b
`B100`F9d9`f`b
`B100`F9d9 ConstantPoolInfo[constantPoolCount - 1] constantPool;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 accessFlags;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 thisClass;`f`b
`B100`F9d9 u2 superClass;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 interfacesCount;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2[interfacesCount] interfaces;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 fieldsCount;`f`b
`B100`F9d9 FieldInfo[fieldsCount] fields;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 methodsCount;`f`b
`B100`F9d9 MethodInfo[methodsCount] methods;`f`b
`B100`F9d9`f`b
`B100`F9d9 u2 attributesCount;`f`b
`B100`F9d9 AttributeInfo[attributesCount] attributes;`f`b
`B100`F9d9}`f`b

>>>The constant pool

The constant pool table is where most of the literal constant values are stored. This includes values such as numbers of all sorts, strings, identifier names, references to classes and methods, and type descriptors. All indexes, or references, to specific constants in the constant pool table are given by 16-bit (type u2) numbers, where index value 1 refers to the first constant in the table (index value 0 is invalid).

Due to historic choices made during the file format development, the number of constants in the constant pool table is not actually the same as the constant pool count which precedes the table. First, the table is indexed starting at 1 (rather than 0), but the count should actually be interpreted as the maximum index plus one.`:cite-ref-jvms-4-4-6-0[`F5bf`_`[6`#cite-note-jvms-4-4-6]`_`f] Additionally, two types of constants (longs and doubles) take up two consecutive slots in the table, although the second such slot is a phantom index that is never directly used.

The type of each item (constant) in the constant pool is identified by an initial byte `*tag`*. The number of bytes following this tag and their interpretation are then dependent upon the tag value. The valid constant types and their tag values are:

`t
| Tag byte | Additional bytes | Description of constant | Version introduced |
|---|---|---|---|
| 1 | 2+ x bytes (variable) | UTF-8 (Unicode) string: a character str… | 1.0.2 |
| 3 | 4 bytes | Integer: a signed 32-bit two's compleme… | 1.0.2 |
| 4 | 4 bytes | Float: a 32-bit single-precision IEEE 7… | 1.0.2 |
| 5 | 8 bytes | Long: a signed 64-bit two's complement… | 1.0.2 |
| 6 | 8 bytes | Double: a 64-bit double-precision IEEE… | 1.0.2 |
| 7 | 2 bytes | Class reference: an index within the co… | 1.0.2 |
| 8 | 2 bytes | String reference: an index within the c… | 1.0.2 |
| 9 | 4 bytes | Field reference: two indexes within the… | 1.0.2 |
| 10 | 4 bytes | Method reference: two indexes within th… | 1.0.2 |
| 11 | 4 bytes | Interface method reference: two indexes… | 1.0.2 |
| 12 | 4 bytes | Name and type descriptor: two indexes t… | 1.0.2 |
| 15 | 3 bytes | Method handle: this structure is used t… | 7 |
| 16 | 2 bytes | Method type: this structure is used to… | 7 |
| 17 | 4 bytes | Dynamic: this is used to specify a dyna… | 11 |
| 18 | 4 bytes | InvokeDynamic: this is used by an invok… | 7 |
| 19 | 2 bytes | Module: this is used to identify a modu… | 9 |
| 20 | 2 bytes | Package: this is used to identify a pac… | 9 |
`t

There are only two integral constant types, integer and long. Other integral types appearing in the high-level language, such as boolean, byte, and short must be represented as an integer constant.

Class names in Java, when fully qualified, are traditionally dot-separated, such as "java.lang.Object". However within the low-level Class reference constants, an internal form appears which uses slashes instead, such as "java/lang/Object".

The Unicode strings, despite the moniker "UTF-8 string", are not actually encoded according to the Unicode standard, although it is similar. There are two differences (see `F33f`_`[UTF-8`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=UTF-8]`_`f for a complete discussion). The first is that the code point U+0000 is encoded as the two-byte sequence `B100`F9d9C0 80`f`b (in hex) instead of the standard single-byte encoding `B100`F9d900`f`b. The second difference is that supplementary characters (those outside the `F33f`_`[BMP`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Basic_Multilingual_Plane]`_`f at U+10000 and above) are encoded using a surrogate-pair construction similar to `F33f`_`[UTF-16`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=UTF-16]`_`f rather than being directly encoded using UTF-8. In this case each of the two surrogates is encoded separately in UTF-8. For example, U+1D11E is encoded as the 6-byte sequence `B100`F9d9ED A0 B4 ED B4 9E`f`b, rather than the correct 4-byte UTF-8 encoding of `B100`F9d9F0 9D 84 9E`f`b.

>>See also

• `F33f`_`[Java bytecode`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_bytecode]`_`f

>>References

`:cite-note-1`!1.`! `F0af`_`[↑`#cite-ref-1]`_`f JSR 202 Java Class File Specification Update
`:cite-note-2`!2.`! `F0af`_`[↑`#cite-ref-2]`_`f James Gosling private communication to Bill Bumgarner
`:cite-note-3`!1.`! "Table 4.1-A. class file format major versions".
`:cite-note-4`!2.`! "JDK 10 Release Notes".
`:cite-note-5`!3.`! "[JDK-8148785] Update class file version to 53 for JDK-9 - Java Bug System".
`:cite-note-jvms-4-4-6`!6.`! `F0af`_`[↑`#cite-ref-jvms-4-4-6-0]`_`f "Chapter 4. The class File Format".

>>Further reading

• `:citereftim-lindholm-frank-yellin1999`aTim Lindholm, Frank Yellin (1999). `*The Java Virtual Machine Specification`* (Second ed.). Prentice Hall. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 0-201-43294-3. Retrieved 2008-10-13. The official defining document of the `F33f`_`[Java Virtual Machine`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_virtual_machine]`_`f, which includes the class file format. Both the first and second editions of the book are freely available online for viewing and/or download.

`c`F0af`_`[↑ Back to top`#top]`_`f`a